/*
 * @Author: wuqingchun
 * @Date: 2024-03-21 09:53:56
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-03-24 17:32:27
 */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>

#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>

void Split(const std::string& refPath, std::vector<std::string>& refVecStr, char cSplit)
{
    std::string strTemp = refPath;
    size_t ulPos;

    while (!strTemp.empty())
    {
        ulPos = strTemp.find(cSplit);
        if (ulPos == (size_t)-1)
        {
            refVecStr.emplace_back(strTemp);
            break;
        }

        if (ulPos == 0)
        {
            refVecStr.emplace_back(strTemp.substr(0, 1));
        }
        else
        {
            refVecStr.emplace_back(strTemp.substr(0, ulPos));
        }

        strTemp = strTemp.substr(ulPos + 1);
    }
}

inline int32_t CreateDirectory(const std::string& refPath)
{
    std::vector<std::string> vecNames;

    Split(refPath, vecNames, '/');

    int32_t iErr;

    std::string strPath{};

    for (auto name : vecNames)
    {
        std::cout << name << std::endl;
        strPath.append(name).append("/");
        //std::cout << strPath << std::endl;

        iErr = mkdir(strPath.c_str(), S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
        if (iErr != 0 && errno != EEXIST)
        {
            printf("Failed to create directory %s, %s\n", name.c_str(), strerror(errno));
            break;
        }

        iErr = 0;
    }


    return 0;
}